grammar Process;

options {
  language = Java;
//  output=AST;
//  ASTLabelType=CommonTree;
}
@header {
  package process.gen;
  import process.ast.Workflow;
  import process.ast.Process;
  import process.ast.Action;
  import process.ast.States;
}
@lexer::header {
  package process.gen;
}

process returns[Process process]
  : {Process p;} 'process' IDENT {p=new Process($IDENT.text);}
  '{' 
    (workflow {p.addWorkflow($workflow.workflow);})*
  '}'
  {return p;}
  ; 
  

workflow returns [Workflow workflow]
  : {Workflow w;} 'workflow' IDENT {w = new Workflow($IDENT.text);}
  '{'
    (action {w.addAction($action.action);})+
  '}' 
  {return w;}
  ;

action returns [Action action]
  :{Action a;}
  IDENT{a = new Action($IDENT.text);} '=' 
  (states {a.addStates($states.states);})+  
//     ( action_opt )? 
  {return a;}
  ;

  
states returns [States states]
  :{States s = new States();} 
    a=IDENT{s.addBeginState($a.text);} 
    (',' b=IDENT{s.addBeginState($b.text);})* 
    '->' end=IDENT{s.setEndState($end.text);}
    {return s;}  
  ;


  
IDENT : ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9' )*;
PERMISSION :('TICKET_VIEW'|'TICKET_CREATE'|'TICKET_MODIFY'|'TRAC_ADMIN');
WHITESPACE: (' '|'\t'|'\n'|'\r'|'\f')+ {$channel = HIDDEN;}; 